﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Radar;
using Jage.Editor.Logic;

namespace Jage.Editor
{
    public partial class NewMapPropertiesForm : Form
    {
        public NewMapPropertiesForm()
        {
            InitializeComponent();
        }
        
        private void NewMapPropertiesForm_Load(object sender, EventArgs e)
        {
            comboBoxThemes.DisplayMember = "Name";
            comboBoxThemes.ValueMember = "Filename";
            comboBoxThemes.DataSource = Configuration.Default.ThemeDefinitions;
        }

        private MapDefinition _mapDefinition;
        public MapDefinition MapDefinition
        {
            get
            {
                if (_mapDefinition == null) _mapDefinition = new MapDefinition();
                FillMapDefinitionFromForm();
                return _mapDefinition;
            }
            set
            {
                _mapDefinition = value;
                FillFormFromMapDefinition();
            }
        }

        private void FillFormFromMapDefinition()
        {
            numericUpDownMapWidth.Value = _mapDefinition.Width;
            numericUpDownMapHeight.Value = _mapDefinition.Height;
            textBoxName.Text = _mapDefinition.Name;
            textBoxDescription.Text = _mapDefinition.Description;
        }

        private void FillMapDefinitionFromForm()
        {
            _mapDefinition.Width = (int)numericUpDownMapWidth.Value;
            _mapDefinition.Height = (int)numericUpDownMapHeight.Value;
            _mapDefinition.Name = textBoxName.Text;
            _mapDefinition.Description = textBoxDescription.Text;
            _mapDefinition.ThemeFilename = ((ThemeDefinition)comboBoxThemes.SelectedItem).Filename;
            Theme.SetCurrentTheme((string)comboBoxThemes.SelectedValue);
            TerrainGenerator.Instance.FillTerrain(_mapDefinition, Theme.Current, (byte)trackBar1.Value);
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            labelFoliage.Text = trackBar1.Value + " %";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBoxName.Text == string.Empty)
            {
                DialogResult = System.Windows.Forms.DialogResult.None;
                MessageBox.Show("Please enter a name for the new map.", "No name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBoxName.Focus();
            }
        }

    }

}